import { Injectable } from '@angular/core';
import { BaseRequestOptions, RequestOptions } from '@angular/http';

@Injectable()
export class DefaultRequestOptions extends BaseRequestOptions {

  constructor() {
    super();

    // Set the default 'Content-Type' header
    this.headers.set("Content-Type", 'application/json');
    // this.headers.set("Access-Control-Allow-Headers","x-requested-with,content-type");
    // this.headers.set("Access-Control-Allow-Origin","*");//允许请求跨域
    // this.responseType=1;
    // console.log( "this.headers");
    // console.log( this.headers);
    // response.setHeader("Access-Control-Allow-Origin", "*"); //允许哪些url可以跨域请求到本域
	// response.setHeader("Access-Control-Allow-Methods","POST"); //允许的请求方法，一般是GET,POST,PUT,DELETE,OPTIONS
	// response.setHeader("Access-Control-Allow-Headers","x-requested-with,content-type"); //允许哪些请求头可以跨域

//      Access-Control-Allow-Origin: http://foo.org

// Access-Control-Max-Age: 3628800

// Access-Control-Allow-Methods: GET，PUT, DELETE

// Access-Control-Allow-Headers: content-type

// "Access-Control-Allow-Origin"表明它允许"http://foo.org"发起跨域请求

// "Access-Control-Max-Age"表明在3628800秒内，不需要再发送预检验请求，可以缓存该结果

// "Access-Control-Allow-Methods"表明它允许GET、PUT、DELETE的外域请求

// "Access-Control-Allow-Headers"表明它允许跨域请求包含content-type头
  }
}

export const requestOptionsProvider = { provide: RequestOptions, useClass: DefaultRequestOptions };
